fix(app): recover from a silently dead event stream - #39349
Open
Luppa90 wants to merge 1 commit into
Open
Conversation
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
The SSE read has no timeout, so a socket that dies without a FIN or RST leaves the consumer parked forever: no error is thrown, the reconnect loop is never re-entered, and the UI freezes mid-message while the run continues server-side. Heartbeats did not help because the v2 server sends them as SSE comment frames, which the parser discards without yielding an event, so liveness was invisible to the app. Track liveness at the byte level instead and abort an attempt after 45s of silence, dropping into the existing reconnect path. Reconnecting alone was not enough. Session status is driven purely by session.execution.* events, so a run that finished during the outage stayed busy forever, and the only resync hook fired solely on the first connect because it was gated on the active-sessions query being unfetched. Reconcile against the server on every reconnect: clear status for runs that are no longer active and reload the timelines held locally. Reload by what is held locally rather than by status. A directory bootstrap also rewrites session_status from the server on reconnect, and when it lands first a finished session already reads idle, so keying the reload off status would clear the spinner while leaving the timeline frozen mid-message.
Luppa90
force-pushed
the
fix-event-stream-stall
branch
from
July 28, 2026 20:12
b9a3cfb to
31d07d4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #39352
Type of change
What does this PR do?
Fixes the web UI freezing mid-session: the spinner keeps spinning, the timeline stops, and only a page refresh reveals the run finished long ago.
Two defects compound.
A dead event stream is undetectable. The SSE consumer reads the response body with no timeout, so a socket that dies without a FIN/RST parks
reader.read()forever — no error is thrown, so the reconnect loop inserver-sdk.tsxis never re-entered. Heartbeats can't help, because v2 sends them as SSE comment frames, which the parser discards without yielding an event, leaving liveness invisible at the event level. So this tracks the stream at the byte level (comment frames included) via a fetch wrapper, and a per-attempt watchdog aborts after 45s of silence — 3 missed heartbeats — dropping into the existing reconnect path. The watchdog aborts a controller captured per attempt, so a stale timer can't kill a healthy successor connection.Reconnecting alone repairs nothing.
session_statusis written only bysession.execution.*events, so a run that finishes during the outage staysbusyforever, and the active-sessions refetch was gated on the query having no data — meaning it only ever fired on the first connect. Now every reconnect refetches and reconciles against the server.The reload set is keyed off sessions that currently hold messages, not off status. That is deliberate:
bootstrapDirectoryalso rewritessession_statusfrom the server on reconnect and then callsresolve(), which refreshes session info but never messages. When that lands first, a finished session already readsidle, so a status-keyed reload skips it — clearing the spinner while leaving the timeline frozen mid-message. Keying off locally-held messages is immune to that ordering. Sessions inretrykeep their status, since retries run inside the execution fiber and the server still reports them active on both protocols.How did you verify your code works?
idle: 45038) and reconnecting cleanly, which confirmed detection was working and the repair was not.session-timeline-transport.spec.ts,remote-tab-busy.spec.ts), including reconnect-after-close, reconnect-after-error, and heartbeat delivery.bun testfor the app package, typecheck, prettier and oxlint are clean. The only failing test is the pre-existingari18n parity gap, which fails identically ondev.Screenshots / recordings
Not a visual change — the fix is that the timeline and spinner recover on their own after a dead connection, instead of freezing until a manual refresh.
Checklist